package com.ypj.community.controller;

import com.ypj.community.dao.DiscussPostMapper;
import com.ypj.community.util.CommunityUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

@Controller
public class test {
    @Resource
    private DiscussPostMapper discussPostMapper;
    @RequestMapping("/user")
    @ResponseBody
    public String message(){
        return "count"+discussPostMapper.selectDiscussPostRows(0);
    }
    @RequestMapping("/cookie")
    @ResponseBody
    public String cookie(HttpServletResponse response){
        //创建cookie
        Cookie cookie=new Cookie("code","sdada");
        //设置生效范围
        cookie.setPath("/community");
        cookie.setMaxAge(60*10);
        response.addCookie(cookie);
        return "sdada";
    }

    //ajax
    @RequestMapping(value = "/ajax",method = RequestMethod.POST)
    @ResponseBody
    public String testAjax(String name,int age){
        System.out.println(name);
        System.out.println(age);
        return CommunityUtil.getJSONString(0,"操作成功");
    }
}
